package com.example.demo.controller;

import com.example.demo.entity.Customer;
import com.example.demo.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.core.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController implements BaseController<Customer> {

    @Autowired
    CustomerService customerService;

    @GetMapping("/{id}")
    public Customer findByID(@PathVariable(value = "id")  int id) {

        return customerService.findByID(id);
    }

    @GetMapping("/")
    public List<Customer> findAll() {
        return customerService.findAll();
    }

    @PostMapping
    public Customer save(@RequestBody  Customer customer) {
        return customerService.save(customer);
    }

    @DeleteMapping("/{id}")
    public boolean deleteByid(@PathVariable(value = "id") int id) {
        boolean b = customerService.deleteByid(id);
        return b;
    }



    @PutMapping("")
    public Customer updateById(@RequestBody  Customer customer) {
        System.out.println(customer);
        Customer customer1 = customerService.updateById(customer);
        return customer1;
    }

    @GetMapping("/findAllByPage/{pageNum}")
    public Page<Customer> findAllByPage(@PathVariable  int pageNum) {
        return customerService.findAllByPage(--pageNum);

    }
}
